<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://"
			+ request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
%>
<!--css-->
<link type="text/css" href="<%=basePath%>static/bootstrap/css/bootstrap.css" rel="stylesheet" />
<!--bootstrap-responsive-->
<link type="text/css" ref="<%=basePath%>static/bootstrap/css/bootstrap-responsive.css" rel="stylesheet" />
<link type="text/css" href="<%=basePath%>static/jquery-loadmask-0.4/jquery.loadmask.css" rel="stylesheet" />
<link type="text/css" href="<%=basePath%>static/jquery-validation/1.9.0/validate.css" rel="stylesheet" />
<!--bootstrap-->
<script type="text/javascript" src="<%=basePath%>static/js/jquery.js"></script>
<script type="text/javascript" src="<%=basePath%>static/jquery-loadmask-0.4/jquery.loadmask.min.js"></script>
<script type="text/javascript" src="<%=basePath%>static/bootstrap/js/bootstrap.js"></script>
<script language="javascript" type="text/javascript" src="<%=basePath%>static/My97DatePicker/WdatePicker.js"></script>
<script type="text/javascript" src="<%=basePath%>static/jquery-validation/1.9.0/jquery.validate.min.js"></script>
<script type="text/javascript" src="<%=basePath%>static/jquery-validation/1.9.0/messages_bs_cn.js"></script>
<script type="text/javascript" src="<%=basePath%>static/Highcharts-2.3.3/js/highcharts.js"></script>
<script type="text/javascript" src="<%=basePath%>static/Highcharts-2.3.3/js/modules/exporting.js"></script>
<script type="text/javascript">
    var basePath = '<%=basePath%>';

    function mask(){
    	$('#view').mask("加载中...");
    }
    
    function unMask(){
    	$('#view').unmask();
    }
    function go(url){
    	window.location.href=basePath+url;
    }
    function go_form(url,form){
    	var param = $('#'+form+'').serialize();
    	$('#view').load(basePath+url+'&'+param,function(){
        });
    }
    
    function tb_check(){
        if($('#ids').attr("checked")=="checked"){
            $('input[type="checkbox"]').attr("checked",'true');//全选
        }else{
            $('input[type="checkbox"]').removeAttr('checked');
        }
    }
    
    function edit(url){
        var ids = $('input[name="ids"]:checked');
        if(ids.size()>1){
            alert('编辑一个');
        }else if(ids.size()==1){
            go(url+'&ids='+ids.val());
        }
    }
    
    function view(url){
        var ids = $('input[name="ids"]:checked');
        if(ids.size()>1){
            alert('查看一个');
        }else if(ids.size()==1){
            go(url+'&ids='+ids.val());
        }
    }
    
    function add(url){
    	go(url);
    }
    
    function approval(url){
    	edit(url);	
    }
    function mrp(url){
    	edit(url);
    }
    
    function del(url){
        var ids = $('input[name="ids"]:checked');
        if(ids.size()>0){
            var str = "";
            ids.each(function(){
                str +=$(this).val()+",";
            });
            str = str.substring(0,str.length-1);
            go(url+'&ids='+str);
        }
    }
    
    function goView(url){
    	/* mask();
    	$('#view').load(basePath+url,function(){
    		unMask();
    	}); */
    	$('#view').empty();
    	$('#view').append('<iframe marginheight="0" marginwidth="0" scrolling="auto" align="center" height="600px;"  id="win" name="win" frameborder="0" src="'+basePath+url+'" class="span12"></iframe>'	);
    	//onload="dyniframesize(\'win\')"
    }
   

	function dyniframesize(down) {
		var pTar = null;
		if (document.getElementById) {
			pTar = document.getElementById(down);
		} else {
			eval('pTar = ' + down + ';');
		}
		if (pTar && !window.opera) {
			//begin resizing iframe 
			pTar.style.display = "block";
			if (pTar.contentDocument && pTar.contentDocument.body.offsetHeight) {
				//ns6 syntax 
				pTar.height = pTar.contentDocument.body.offsetHeight + 40;
				pTar.width = pTar.contentDocument.body.scrollWidth + 20;
			} else if (pTar.Document && pTar.Document.body.scrollHeight) {
				//ie5+ syntax 
				pTar.height = pTar.Document.body.scrollHeight+20;
				pTar.width = pTar.Document.body.scrollWidth;
			}
		}
	}

	function goShow() {
		//$('#view').load(basePath + "view/show.jsp");
		goView('view/show.jsp');
	}

	function goMenu() {
		$('#view').load(basePath + 'view/myjsp.jsp');
	}

	function goFile() {
		$('#view').load(basePath + 'view/myfile.jsp');
	}
	function goStore() {
		$('#view').load(basePath + 'storem/store?list');
	}

	function tologin() {
		window.location.href = basePath;
	}

	function close_page() {
		self.opener = null;
		self.open('', '_self');
		self.close();
	}

	/*分页  */
	function first_page() {
		$('input[name="pageNum"]').val(1);
		var url = $('#form').attr("action");
		go(url + '&' + $('#form').serialize());
	}

	function last_page() {
		$('input[name="pageNum"]').val($('input[name="totalPage"]').val());
		var url = $('#form').attr("action");
		go(url + '&' + $('#form').serialize());
	}

	function first_Dpage() {
		$('input[name="pageNum"]').val(1);
		var url = $('#dialogForm').attr("action");
		model_show(url + '&' + $('#dialogForm').serialize());
	}

	function last_Dpage() {
		$('input[name="pageNum"]').val($('input[name="totalPage"]').val());
		var url = $('#dialogForm').attr("action");
		model_show(url + '&' + $('#dialogForm').serialize());
	}

	function form_submit(url) {
		$('#form').submit(function() {
			jQuery.ajax({
				url : '<%=basePath%>'+url,
	                data:$('#form').serialize(),
	                target:'main',
	                type:'post',
	                beforeSend:function(){
	                    mask();
	                },
	                success:function(url){
						unMask();
	                	go(url);
	                },
	                error: function(XMLHttpRequest, textStatus, errorThrown) {
	                    alert(XMLHttpRequest.status);
	                    alert(XMLHttpRequest.readyState);
	                    alert(textStatus);
	                }
	            });
	            return false;
	        });
	    }
	
	function fileForm_submit(url){
        $('#form').submit(function(){
            jQuery.ajax({
                url:'<%=basePath%>'+url,
                data:$('#form').serialize(),
                target:'main',
                type:'post',
                fileElementId:'file',
                beforeSend:function(){
                    //new screenClass().lock();
                },
                success:function(url){
                    //new screenClass().unlock();
                    go(url);
                },
                error: function(XMLHttpRequest, textStatus, errorThrown) {
                    alert(XMLHttpRequest.status);
                    alert(XMLHttpRequest.readyState);
                    alert(textStatus);
                }
            });
            return false;
        });
    }
	    
	    function goPage(num){
	        $('input[name="pageNum"]').val(num);
	        var url = $('#form').attr("action");
	        go(url+'&'+$('#form').serialize());
	    }
	    
	    function goDialog(num){
	    	$('input[name="pageNum"]').val(num);
	        var url = $('#dialogForm').attr("action");
	        model_show(url+'&'+$('#dialogForm').serialize());
	        //go(url+'&'+$('#dialogForm').serialize());
	    }
	    function model_show(url){
	    	$('#myModal').modal('show');
	    	$('#model_body').load('<%=basePath%>' + url);
	}

	var id ;
	var text;
	//1:单选 2:多选
	var select_num = 1;
	    
	/* function menu_search_father() {
		model_show('system/menu?queryFather');
		id = $('input[name="father.id"]');
		text = $('input[name="father.name"]');
	}
	
	function menu_search_child() {
		model_show('system/menu?queryChild');
		id = $('input[name="menu.id"]');
		text = $('input[name="menu.name"]');
	} */
	
	function search_d(url,obj,num){
		model_show(url);
		text = obj;
		select_num = num;
	}
	var obj_this;
	var materiel_id_table;
	function search_table_d(url,obj,num,obj1,materiel_id){
		model_show(url);
		text = obj;
		select_num = num;
		obj_this = obj1;
		materiel_id_table = materiel_id;
	}
	
	function role_search() {
		model_show('system/role?query');
		id = $('input[name="role_id"]');
		text = $('input[name="role_name"]');
	}

	function returnValue() {
		var ids = $('input[name="ids"]:checked');
		if(select_num==2){
            var idS = "";
            var textS = "";
            ids.each(function(){
            	var data = $(this).val().split(",");
				idS += data[0]+ ",";
				textS += data[1]+ ",";
            });
            idS = idS.length>0?idS.substring(0,idS.length-1):"";
            textS = textS.length>0?textS.substring(0,textS.length-1):"";
            
            var text_s = text.split(",");
            $('input[name="'+text_s[0]+'"]').val(idS);
            $('input[name="'+text_s[1]+'"]').val(textS);
    		/* id.val(idS);
    		text.val(textS); */
        }else if(select_num==1){
        	var data = ids.val().split(",");
        	for(var i=0;i<text.split(",").length;i++){
				$('input[name="'+text.split(",")[i]+'"]').val(data[i]);
			}
    		/* id.val(data[0]);
    		text.val(data[1]); */
        }else if(select_num==3){
        	var data = ids.val().split(",");
        	for(var i=0;i<text.split(",").length;i++){
				$('input[name="'+text.split(",")[i]+'"]').val(data[i]);
			}
        	$(obj_this).parent().parent().find('[name="'+materiel_id_table+'"]').val(data[0]);
        }
		$('#myModal').modal('hide');
	}
	
	function selectItem(kind,obj,id){
		$.ajax({
			type:'post',
			async:false,
			url:basePath+'system/dataDic?query&kind='+kind,
			success:function(data,status){
				data = eval(data);
				$.each(data,function(i,o){
					if(obj==o.value)
						$('#'+id+'').append('<option value='+o.value+' selected="selected">'+o.label+'</option>');
					else
						$('#'+id+'').append('<option value='+o.value+'>'+o.label+'</option>');
				});
			}
		});
	}
</script>

